{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Maximum Number of Balloons"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #hash-table #string #counting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #哈希表 #字符串 #计数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: maxNumberOfBalloons"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #“气球” 的最大数量"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个字符串&nbsp;<code>text</code>，你需要使用 <code>text</code> 中的字母来拼凑尽可能多的单词&nbsp;<strong>&quot;balloon&quot;（气球）</strong>。</p>\n",
    "\n",
    "<p>字符串&nbsp;<code>text</code> 中的每个字母最多只能被使用一次。请你返回最多可以拼凑出多少个单词&nbsp;<strong>&quot;balloon&quot;</strong>。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<p><strong><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/09/14/1536_ex1_upd.jpeg\" style=\"height: 35px; width: 154px;\"></strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>text = &quot;nlaebolko&quot;\n",
    "<strong>输出：</strong>1\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<p><strong><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/09/14/1536_ex2_upd.jpeg\" style=\"height: 35px; width: 233px;\"></strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>text = &quot;loonbalxballpoon&quot;\n",
    "<strong>输出：</strong>2\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>text = &quot;leetcode&quot;\n",
    "<strong>输出：</strong>0\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= text.length &lt;= 10^4</code></li>\n",
    "\t<li><code>text</code>&nbsp;全部由小写英文字母组成</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [maximum-number-of-balloons](https://leetcode.cn/problems/maximum-number-of-balloons/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [maximum-number-of-balloons](https://leetcode.cn/problems/maximum-number-of-balloons/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"nlaebolko\"', '\"loonbalxballpoon\"', '\"leetcode\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        \n",
    "        text_dict = collections.Counter(text)\n",
    "        if text_dict[\"l\"]%2==1:\n",
    "            text_dict[\"l\"] -= 1\n",
    "        text_dict[\"l\"] //=2\n",
    "        if  text_dict[\"o\"]%2==1:\n",
    "            text_dict[\"o\"] -= 1\n",
    "        text_dict[\"o\"] //=2\n",
    "        b_num = text_dict.get('b',0)\n",
    "        a_num = text_dict.get('a',0)\n",
    "        l_num = text_dict.get('l',0)\n",
    "        o_num = text_dict.get('o',0)\n",
    "        n_num = text_dict.get('n',0)\n",
    "        return min([b_num, a_num, l_num, o_num, n_num])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        word_count = Counter(list(text))\n",
    "        ans = inf\n",
    "        for char in 'ban':\n",
    "            ans = min(ans, word_count[char])\n",
    "        for char in 'lo':\n",
    "            ans = min(ans, word_count[char] // 2)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        dic = {}\n",
    "        for i in 'balloon':\n",
    "            dic[i] = 0\n",
    "        for i in text:\n",
    "            if i in 'balloon':\n",
    "                dic[i] += 1\n",
    "        dic['l'] = dic['l']//2\n",
    "        dic['o'] = dic['o']//2\n",
    "        return min(dic.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        cnt = Counter(ch for ch in text if ch in \"balon\")\n",
    "        cnt['l'] //= 2\n",
    "        cnt['o'] //= 2\n",
    "        return min(cnt.values()) if len(cnt) == 5 else 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import collections \n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        d=Counter(text)\n",
    "        res=inf\n",
    "        for s in  \"balloon\":\n",
    "\n",
    "\n",
    "            if s=='l' or s=='o':\n",
    "                 res=min(res,d.get(s,0)//2)\n",
    "            else:\n",
    "                res=min(res,d.get(s,0))\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        balon_dict = {'b':0,'a':0,'l':0,'o':0,'n':0}\n",
    "        for i in text:\n",
    "            if i in balon_dict:\n",
    "                balon_dict[i]+=1\n",
    "        return min(balon_dict['b'], balon_dict['a'], int(balon_dict['l']/2), int(balon_dict['o']/2), balon_dict['n'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        cnt = Counter(ch for ch in text if ch in \"balon\")\n",
    "        cnt['l'] //= 2\n",
    "        cnt['o'] //= 2\n",
    "        return min(cnt.values()) if len(cnt) == 5 else 0\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        c = Counter(text)\n",
    "        return min(c['b'], c['a'], c['l'] // 2, c['o'] // 2, c['n'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        # 统计出现balon单词的数量，返回其中出现最少次数的数，其中l和o的次数要做/2\n",
    "        ans = Counter(text)\n",
    "        return int(min(ans[\"b\"],ans[\"a\"],ans[\"l\"]/2,ans[\"o\"]/2,ans[\"n\"]))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        word = 'balloon'\n",
    "        counts = {char: text.count(char) for char in word}\n",
    "        counts['l'] //= 2  # 修复 'l' 的计数\n",
    "        counts['o'] //= 2  # 修复 'o' 的计数\n",
    "        min_count = min(counts.values())\n",
    "        return min_count\n",
    "# class Solution:\n",
    "#     def maxNumberOfBalloons(self, text: str) -> int:\n",
    "#         hashtable = dict()\n",
    "#         for char in text:\n",
    "#             if char in hashtable.keys():\n",
    "#                 hashtable[char] += 1\n",
    "#             else:\n",
    "#                 hashtable[char] = 1\n",
    "#         count = 0\n",
    "#         chars = \"balloon\" \n",
    "#         n = len(text)//len(chars)\n",
    "#         res = 0\n",
    "#         for _ in range(n):\n",
    "#             count = 0\n",
    "#             for char in chars:\n",
    "#                 if hashtable.get(char):\n",
    "#                     hashtable[char] -= 1\n",
    "#                     count += 1\n",
    "#                 else:\n",
    "#                     continue\n",
    "            \n",
    "#             if count == len(chars):\n",
    "#                 res += 1\n",
    "#         return res\n",
    "\n",
    "# class Solution:\n",
    "#     def maxNumberOfBalloons(self, text: str) -> int:\n",
    "#         hashtable = {}\n",
    "#         for c in text:\n",
    "#             hashtable[c] = hashtable.get(c, 0) + 1\n",
    "#         word = 'balloon'\n",
    "#         word_table = {}  \n",
    "#         for w in word:\n",
    "#             word_table[w] = word_table.get(w, 0) + 1 \n",
    "#         count = []\n",
    "#         for w in word:\n",
    "#             num = hashtable.get(w,0) // word_table[w]\n",
    "#             count.append(num)\n",
    "#         return int(min(count))\n",
    "# class Solution:\n",
    "#     def maxNumberOfBalloons(self, text: str) -> int:\n",
    "#         hashtable = {}\n",
    "#         for c in text:\n",
    "#             hashtable[c] = hashtable.get(c, 0) + 1\n",
    "#         word = 'balloon'\n",
    "#         word_table = {}\n",
    "#         for w in word:\n",
    "#             word_table[w] = word_table.get(w, 0) + 1\n",
    "#         count = []\n",
    "#         for w in word:\n",
    "#             num = hashtable.get(w, 0) / word_table[w]\n",
    "#             count.append(num)\n",
    "#         return int(min(count))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        c=Counter(text)\n",
    "        c2=Counter('balloon')\n",
    "        res=[]\n",
    "        for i in c2:\n",
    "            res.append(c[i]//c2[i])\n",
    "            c[i]%=c2[i]\n",
    "        return min(res)\n",
    "\n",
    "\n",
    "        \n",
    "        \n",
    "        \n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        ch = defaultdict(int)\n",
    "        for c in text:\n",
    "            ch[c] += 1\n",
    "        return min(ch['a'], ch['b'], ch['n'], ch['l'] //2, ch['o']//2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        temp = {}\n",
    "        for i in \"balloon\":\n",
    "            if temp.get(i)==None:\n",
    "                temp[i] = 0\n",
    "        for j in text:\n",
    "            if temp.get(j)!=None:\n",
    "                temp[j] +=1\n",
    "        temp['l'] //=2\n",
    "        temp['o'] //=2\n",
    "        res = temp.values()\n",
    "        res = list(res)\n",
    "\n",
    "        return min(res)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        return min(cnts[c]//2 if c in \"lo\" else cnts[c] for c in \"balon\") if (cnts := Counter(text)) else 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        bal = {\"b\": 1, \"a\": 1, \"l\":2, \"o\":2, \"n\":1}\n",
    "        count = {}\n",
    "        for c in text:\n",
    "            if c in \"balon\":\n",
    "                count[c] = count.get(c, 0) + 1 \n",
    "    \n",
    "        for c, n in bal.items():\n",
    "            bal[c] = count.get(c, 0) // bal[c]\n",
    "        return min(bal.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        h = {'b':0,'a':0,'l':0,'o':0,'n':0}\n",
    "        for i in text:\n",
    "            if i in ['b','a','n']:\n",
    "                h[i] += 1\n",
    "            elif i in ['l','o']:\n",
    "                h[i] += 0.5\n",
    "        return int(min(i for i in h.values()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int: \n",
    "        d = {c:0 for c in 'balon'}\n",
    "        for c in text:\n",
    "            if c in 'balon':\n",
    "                d[c] += 1\n",
    "\n",
    "        return min(d[c]//2 if c in ['o', 'l'] else d[c] for c in d)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        cnt = Counter()\n",
    "        for x in text:\n",
    "            cnt[x] += 1\n",
    "        return min(cnt[\"b\"], cnt[\"a\"], cnt[\"l\"] // 2, cnt[\"o\"] // 2, cnt[\"n\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        counter = Counter(text)\n",
    "        cnt = 0\n",
    "        while True:\n",
    "            for i in \"balloon\":\n",
    "                if i in counter and counter[i] > 0:\n",
    "                    counter[i] -= 1\n",
    "                else:\n",
    "                    return cnt\n",
    "            cnt += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "\n",
    "        text_count = dict(collections.Counter(text))\n",
    "        ballon_count = dict(collections.Counter(\"balloon\"))\n",
    "\n",
    "        min_count = float('inf')\n",
    "        for c in ballon_count:\n",
    "            count = text_count.get(c, 0) // ballon_count[c]\n",
    "            min_count = min(min_count, count)\n",
    "        \n",
    "        return min_count\n",
    "\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        counter = Counter(text)\n",
    "        cnt = 0\n",
    "        while True:\n",
    "            for i in \"balloon\":\n",
    "                if i in counter and counter[i] > 0:\n",
    "                    counter[i] -= 1\n",
    "                else:\n",
    "                    return cnt\n",
    "            cnt += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        cnt = Counter(text)\n",
    "        ans = inf\n",
    "        ans = min(ans, cnt['b'])\n",
    "        ans = min(ans, cnt['a'])\n",
    "        ans = min(ans, cnt['l']//2)\n",
    "        ans = min(ans, cnt['o']//2)\n",
    "        ans = min(ans, cnt['n'])\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        cnt = {'a': 0, 'b': 0, 'l': 0, 'n': 0, 'o': 0}\n",
    "        for char in text:\n",
    "            if char in cnt:\n",
    "                cnt[char] += 1\n",
    "        cnt['l'] //= 2\n",
    "        cnt['o'] //= 2\n",
    "        return min(cnt.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import collections\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        d = collections.Counter(text)\n",
    "        return min(d['b'], d['a'], d['l'] // 2, d['o'] // 2, d['n'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        dict1={\n",
    "            \"b\":0,\n",
    "            \"a\":0,\n",
    "            \"l\":0,\n",
    "            \"o\":0,\n",
    "            \"n\":0,\n",
    "        }\n",
    "        for i  in text:\n",
    "            if i in dict1:\n",
    "                dict1[i]+=1\n",
    "        return min(dict1[\"b\"],dict1[\"a\"],dict1[\"l\"]//2,dict1[\"o\"]//2,dict1[\"n\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        cnt = Counter(ch for ch in text if ch in 'balon')\n",
    "        cnt['l'] //= 2\n",
    "        cnt['o'] //= 2\n",
    "        return min(cnt.values()) if len(cnt) == 5 else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        dic = Counter(text)\n",
    "        lst = []\n",
    "        for c in \"balloon\":\n",
    "            lst.append(dic[c] // 2 if c == \"l\" or c == \"o\" else dic[c])\n",
    "        return min(lst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        map = dict(zip(list('balloon'), [0]*7))\n",
    "        for c in text:\n",
    "            if c in map.keys():\n",
    "                map[c] += 1\n",
    "        map['l'] = int(map['l']/2)\n",
    "        map['o'] = int(map['o'] / 2)\n",
    "        return min(map.values())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        count = defaultdict(int)\n",
    "        for st in text:\n",
    "            if st in 'balloon':\n",
    "                count[st] += 1\n",
    "        return min([count['b'] , count['a'] , count['l']//2 , count['o']//2 , count['n']])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        dic = Counter(text)\n",
    "        ans = 0\n",
    "        d = ['b','a','l','l','o','o','n']\n",
    "        key = 1\n",
    "        while True:\n",
    "            for i in d:\n",
    "                if dic[i] > 0:\n",
    "                    dic[i] -= 1\n",
    "                else:\n",
    "                    key = 0\n",
    "            if key == 0:\n",
    "                break\n",
    "            ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        dic = {}\n",
    "        chars = list(\"balloon\")\n",
    "\n",
    "        for ch in text:\n",
    "            if ch in chars:\n",
    "                if ch in dic:\n",
    "                    dic[ch] += 1\n",
    "                else:\n",
    "                    dic[ch] = 1\n",
    "        \n",
    "        res = float(inf)\n",
    "        for ch in chars:\n",
    "            if ch not in dic:\n",
    "                return 0\n",
    "            n = dic[ch]\n",
    "            baseN = 2 if ch in [\"l\", \"o\"] else 1\n",
    "            res = min(res,  n//baseN)\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import defaultdict\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        res = defaultdict(int)\n",
    "        for ch in text:\n",
    "            if ch in \"balon\":\n",
    "                res[ch] += 1\n",
    "        res[\"l\"] //= 2\n",
    "        res[\"o\"] //= 2\n",
    "        num = min(res.values())\n",
    "        return num if len(res) == 5 else 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        dic = {'b':0,'a':0,'l':0,'o':0,'n':0}\n",
    "        for i in text:\n",
    "            if i in 'balloon':\n",
    "                dic[i] +=1\n",
    "        print(dic)\n",
    "        return min(dic['a'],dic['b'],dic['l']//2,dic['o']//2,dic['n'])\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        ad={'b':0,'a':0,'l':0,'o':0,'n':0}\n",
    "        for i in text:\n",
    "            if i in ad:\n",
    "                ad[i]+=1        \n",
    "        ad['l']=ad['l']//2\n",
    "        ad['o']=ad['o']//2\n",
    "        al=[[k,v] for k,v in ad.items()]\n",
    "        al.sort(key=lambda x:(x[1],x[0]))        \n",
    "        return al[0][1]\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        counts = defaultdict(int)\n",
    "        for char in text:\n",
    "            counts[char] += 1\n",
    "        counts['o'] //= 2\n",
    "        counts['l'] //= 2\n",
    "        if counts['b'] >0 and counts['a'] > 0 and counts['l'] > 0 and counts['o'] > 0 and counts['n'] > 0:\n",
    "            return min(counts['b'], counts['a'], counts['l'], counts['o'], counts['n'])\n",
    "        else:\n",
    "            return 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        c = Counter(text)\n",
    "        return min(c[k] // v for k, v in Counter('balloon').items())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        l1 = {\"b\":0, \"a\":0, \"l\":0, \"o\":0, \"n\":0}\n",
    "        for i in range (len(text)):\n",
    "            if text[i] in l1:\n",
    "                l1[text[i]] += 1\n",
    "        l2 = [l1[\"b\"], l1[\"a\"], l1[\"l\"], l1[\"o\"], l1[\"n\"]]\n",
    "        l3 = [1, 1, 2, 2, 1]\n",
    "        target = 0\n",
    "        for i in range (5):\n",
    "            if l2[i] // l3[i] == 0:\n",
    "                return 0\n",
    "            else:\n",
    "                if target == 0:\n",
    "                    target = l2[i] // l3[i]\n",
    "                else:\n",
    "                    target = min(target, l2[i] // l3[i])\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        dic = Counter(text)\n",
    "        ans = 0\n",
    "        while True:\n",
    "            s = 0\n",
    "            for c in \"balloon\":\n",
    "                if c in dic and dic[c] > 0:\n",
    "                    dic[c] -= 1\n",
    "                    s += 1\n",
    "            if s == len(\"balloon\"):\n",
    "                ans += 1\n",
    "            else:\n",
    "                break\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        b = text.count('b')\n",
    "        a = text.count('a')\n",
    "        l = text.count('l')\n",
    "        o = text.count('o')\n",
    "        n = text.count('n')\n",
    "        mn = 0\n",
    "        if not all([b, a, l, o, n]):\n",
    "            return 0\n",
    "        while True:\n",
    "            if mn / b <= 1 and mn / a <= 1 and mn / l * 2 <= 1 and mn / o * 2 <= 1 and mn / n <= 1:\n",
    "                mn += 1\n",
    "            else:\n",
    "                break\n",
    "        return mn-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import defaultdict\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        cnts=defaultdict(int)\n",
    "        for i in 'balloon':cnts[i]=0\n",
    "        for i in text:\n",
    "            if i in 'balloon':\n",
    "                if i in 'lo':cnts[i]+=0.5\n",
    "                else:cnts[i]+=1\n",
    "        return int(min(cnts.values()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        counter = Counter(text)\n",
    "        for ch in 'balloon':\n",
    "            if ch not in counter:\n",
    "                return 0\n",
    "        else:\n",
    "            res = [[k,v] for k,v in counter.items() if k in 'balloon']\n",
    "            for i in res:\n",
    "                if i[0] in 'lo':\n",
    "                    i[1] //= 2\n",
    "            res = [b for a,b in res]\n",
    "            return min(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        c=Counter(text)\n",
    "        return(min(c[x]//n for x,n in Counter('balloon').items()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        res = []\n",
    "        counter = collections.Counter(text)\n",
    "        dict_ballon = {\n",
    "            'a': 1,\n",
    "            'b': 1,\n",
    "            'n': 1,\n",
    "            'l': 2,\n",
    "            'o': 2\n",
    "        }\n",
    "        for key in dict_ballon.keys():\n",
    "            if key in counter:\n",
    "                res.append(counter[key]//dict_ballon[key])\n",
    "            else:\n",
    "                return 0\n",
    "        return min(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        if not text:\n",
    "            return 0\n",
    "        \n",
    "        balloon = {}\n",
    "        letter_count = {}\n",
    "        for letter in \"balloon\":\n",
    "            balloon[letter] = balloon.get(letter, 0) + 1\n",
    "        for letter in text:\n",
    "            letter_count[letter] = letter_count.get(letter, 0) + 1\n",
    "        \n",
    "        res = 0\n",
    "        while True:\n",
    "            for letter in balloon:\n",
    "                if letter_count.get(letter, 0) < balloon[letter]:\n",
    "                    return res\n",
    "                letter_count[letter] -= balloon[letter]\n",
    "            res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        d = {\"b\":0,\"o\":0,\"a\":0,\"l\":0,\"n\":0}\n",
    "        for i in text:\n",
    "            if i in d:\n",
    "                d[i] += 1\n",
    "        min1 = min(d[\"b\"],d[\"o\"]//2,d[\"a\"],d[\"n\"],d[\"l\"]//2)\n",
    "        return min1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        return min(Counter(text)[k] // v for k, v in Counter('balloon').items())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        ST = {\"b\": 1, \"a\": 1, \"l\": 2, \"o\": 2, \"n\": 1}\n",
    "        st = {\"b\": 0, \"a\": 0, \"l\": 0, \"o\": 0, \"n\": 0}\n",
    "        for t in text:\n",
    "            if t in st:\n",
    "                st[t] += 1\n",
    "        min_value = float('inf')\n",
    "        for k, v in st.items():\n",
    "            min_value = min(min_value, st[k] // ST[k])\n",
    "        return min_value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        count=Counter(text)\n",
    "        return min(count['b'],count['a'],count['l']//2,count['o']//2,count['n'])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        return min(text.count(key)//num for key,num in collections.Counter('balloon').items()) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int: \n",
    "        d = {c:0 for c in 'balon'}\n",
    "        for c in text:\n",
    "            if c in 'balon':\n",
    "                d[c] += 1\n",
    "\n",
    "        return min(d[c]//2 if c in ['o', 'l'] else d[c] for c in d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        ans = 0\n",
    "        cnt = collections.Counter(text)\n",
    "        c = collections.Counter('balloon')\n",
    "        while True:\n",
    "            if all(cnt[i] >= c[i] for i in 'balon'):\n",
    "                ans += 1\n",
    "                cnt['b'] -= 1\n",
    "                cnt['a'] -= 1\n",
    "                cnt['l'] -= 2\n",
    "                cnt['o'] -= 2\n",
    "                cnt['n'] -= 1\n",
    "            else:\n",
    "                break\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        dic={}\n",
    "        dic['a']=0\n",
    "        dic['b']=0\n",
    "        dic['l']=0\n",
    "        dic['o']=0\n",
    "        dic['n']=0\n",
    "        for i in range(0,len(text)):\n",
    "            if text[i] in dic:\n",
    "                dic[text[i]]+=1\n",
    "        m_min=len(text)\n",
    "        for k,v in dic.items():\n",
    "            if k=='a' or k=='b' or k=='n':\n",
    "                m_min=min(m_min,v)\n",
    "            if k=='l' or k=='o':\n",
    "                \n",
    "                m_min=min(m_min,int(v/2))\n",
    "        return m_min\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "target = Counter(\"balloon\")\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        cnt = Counter(text)\n",
    "        return min(cnt[k] // target[k] for k in target)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        dic = {\"b\":0,\"a\":0,\"l\":0,\"o\":0,\"n\":0}\n",
    "        for s in text:\n",
    "            if s in dic:\n",
    "                dic[s] += 1\n",
    "\n",
    "        result = 0\n",
    "        while dic[\"l\"] > 1 and dic[\"o\"] > 1 and dic[\"b\"] and dic[\"a\"] and dic[\"n\"]:\n",
    "            result += 1\n",
    "            mapping = {\"l\":2,\"o\":2,\"b\":1,\"a\":1,\"n\":1}\n",
    "            for k, v in mapping.items():\n",
    "                dic[k] -= v\n",
    "\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        ball=Counter('balloon')\n",
    "        t = Counter(text)\n",
    "        res = 9999\n",
    "        for key in ball.keys():\n",
    "            res = min(res,t[key]//ball[key])\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        dic = Counter(text)\n",
    "        lst = []\n",
    "        for c in \"balloon\":\n",
    "            lst.append(dic[c] // 2 if c == \"l\" or c == \"o\" else dic[c])\n",
    "        return min(lst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        cnt = Counter(ch for ch in text if ch in \"balon\")\n",
    "        cnt['l'] //= 2\n",
    "        cnt['o'] //= 2\n",
    "        return min(cnt.values()) if len(cnt) == 5 else 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        need_dir = {\"a\":0, \"b\":0, \"l\":0, \"n\":0, \"o\":0}\n",
    "        a_dir = {\"a\":1, \"b\":1, \"l\":2, \"n\":1, \"o\":2}\n",
    "\n",
    "        count = float(\"inf\")\n",
    "\n",
    "        for i in text:\n",
    "            if i in need_dir:\n",
    "                need_dir[i] += 1\n",
    "        for i in need_dir:\n",
    "            count = need_dir[i] // a_dir[i] if need_dir[i] // a_dir[i] < count else count\n",
    "        return (count)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        h = {'b':0,'a':0,'l':0,'o':0,'n':0}\n",
    "        for i in text:\n",
    "            if i in ['b','a','n']:\n",
    "                h[i] += 1\n",
    "            elif i in ['l','o']:\n",
    "                h[i] += 0.5\n",
    "        return int(min(i for i in h.values()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        dic={'b':0,'a':0,'l':0,'o':0,'n':0}\n",
    "        for i in text:\n",
    "            if i in dic:\n",
    "                dic[i]+=1\n",
    "        dic['l']=int(dic['l']/2)\n",
    "        dic['o']=int(dic['o']/2)\n",
    "        m=dic['a']\n",
    "        for v in dic.values():\n",
    "            if v<m:\n",
    "                m=v\n",
    "        return m\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        count = {}\n",
    "        for s in text:\n",
    "\n",
    "            count[s] = count.get(s, 0) + 1\n",
    "\n",
    "        #arr = ('b','a','l','l','o','o','n')\n",
    "        min_count = float('inf')\n",
    "        for s in 'balloon':\n",
    "            if s not in count:\n",
    "                return 0\n",
    "\n",
    "            if s in ['l', 'o']:\n",
    "                min_count = min(min_count, count[s] // 2)\n",
    "            else:\n",
    "                min_count = min(min_count, count[s])\n",
    "        return min_count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        lst=list(text)\n",
    "        dic={}\n",
    "        for i in lst:\n",
    "            if i in dic:\n",
    "                dic[i]+=1\n",
    "            else:\n",
    "                dic[i]=1\n",
    "        count=0\n",
    "        while True:\n",
    "            if dic.get('b', 0) >= 1 and dic.get('a', 0) >= 1 and dic.get('l', 0) >= 2 and dic.get('o', 0) >= 2 and dic.get('n', 0) >= 1:\n",
    "                count += 1\n",
    "                dic['b'] -= 1\n",
    "                dic['a'] -= 1\n",
    "                dic['l'] -= 2\n",
    "                dic['o'] -= 2\n",
    "                dic['n'] -= 1\n",
    "            else:\n",
    "                break\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        b=text.count('b')\n",
    "        a=text.count('a')\n",
    "        l=text.count('l')//2\n",
    "        o=text.count('o')//2\n",
    "        n=text.count('n')\n",
    "        li=[]\n",
    "        li.append(b)\n",
    "        li.append(a)\n",
    "        li.append(l)\n",
    "        li.append(o)\n",
    "        li.append(n)\n",
    "        x=min(li)\n",
    "        return x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        counter = Counter(text)\n",
    "        cnt = 0\n",
    "        while True:\n",
    "            for i in \"balloon\":\n",
    "                if i in counter and counter[i] > 0:\n",
    "                    counter[i] -= 1\n",
    "                else:\n",
    "                    return cnt\n",
    "            cnt += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        b=text.count(\"b\")\n",
    "        a=text.count(\"a\")\n",
    "        l=text.count(\"l\")//2\n",
    "        o=text.count(\"o\")//2\n",
    "        n=text.count(\"n\")\n",
    "        return min(a,b,o,l,n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        # 统计出现balon单词的数量，返回其中出现最少次数的数，其中l和o的次数要做/2\n",
    "        ans = Counter(text)\n",
    "        return int(min(ans[\"b\"],ans[\"a\"],ans[\"l\"]/2,ans[\"o\"]/2,ans[\"n\"]))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        dic = {}\n",
    "        for c in text:\n",
    "            if c in \"balon\":\n",
    "                dic[c] = dic.get(c, 0) + 1\n",
    "        print (dic)\n",
    "        if 'l' in dic:\n",
    "            dic['l'] //= 2\n",
    "        if 'o' in dic:\n",
    "            dic['o'] //= 2\n",
    "        if len(dic) == 5:\n",
    "            return min(dic.values())\n",
    "        return 0 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        counter = Counter(text)\n",
    "        for ch in 'balloon':\n",
    "            if ch not in counter:\n",
    "                return 0\n",
    "        else:\n",
    "            res = [[k,v] for k,v in counter.items() if k in 'balloon']\n",
    "            for i in res:\n",
    "                if i[0] in 'lo':\n",
    "                    i[1] //= 2\n",
    "            res = [b for a,b in res]\n",
    "            return min(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        return min(text.count('b'),text.count('a'),int(text.count('l')/2),int(text.count('o')/2),text.count('n'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        cnt = Counter(ch for ch in text if ch in \"balon\")\n",
    "        cnt['l'] //= 2\n",
    "        cnt['o'] //= 2\n",
    "        return min(cnt.values()) if len(cnt) == 5 else 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        dct = defaultdict(int)\n",
    "        word = 'balon'\n",
    "        for i in word:\n",
    "            dct[i] = 0\n",
    "        for i in text:\n",
    "            if i in word:\n",
    "                dct[i] += 1\n",
    "        dct['l'] = dct['l']//2\n",
    "        dct['o'] = dct['o']//2\n",
    "        return min(dct.values())\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        dic = {'b':0,'a':0,'l':0,'o':0,'n':0}\n",
    "        for i in text:\n",
    "            if i in dic:\n",
    "                dic[i] += 1\n",
    "        return min(dic['b'],dic['a'],dic['l']//2,dic['o']//2,dic['n'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        counts=Counter(text)\n",
    "        balloon=Counter('balloon')\n",
    "        result=0\n",
    "        for c in balloon:\n",
    "            if c not in counts:\n",
    "                return 0\n",
    "        while True:\n",
    "            for c in balloon:\n",
    "                counts[c]-=balloon[c]\n",
    "                if counts[c]<0:\n",
    "                    return result\n",
    "            result+=1\n",
    "\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        c = Counter(text)\n",
    "        return min(c[k] // v for k, v in Counter('balloon').items())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxNumberOfBalloons(self, text: str) -> int:\n",
    "        from collections import defaultdict\n",
    "        dic = defaultdict(int)\n",
    "        for char in text:\n",
    "            dic[char] += 1\n",
    "        num = []\n",
    "        num.append(dic['b'])\n",
    "        num.append(dic['a'])\n",
    "        num.append(dic['l']//2)\n",
    "        num.append(dic['o']//2)\n",
    "        num.append(dic['n'])\n",
    "        return min(num)"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
